package org.zcq100.db;
import java.sql.*;

public class SqlserverDemo {
	private final static String CLASS_NAME="com.microsoft.sqlserver.jdbc.SQLServerDriver";
	private final static String URL="jdbc:sqlserver://localhost:1433;databaseName=test";
	
	public static Connection getConnection(){
		Connection conn=null;
		try {
			Class.forName(CLASS_NAME);
			conn=DriverManager.getConnection(URL, "sa","123456");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return conn;
	}
	
public static void main(String[] args) {
	Connection conn=getConnection();
	try {
		Statement stmt=conn.createStatement();
		ResultSet res=stmt.executeQuery("select * from [user]");
		while(res.next()){
			System.out.println(res.getString(1)+","+res.getString(2)+","+res.getString(3));
		}
	} catch (Exception e) {
		e.printStackTrace();
	}finally{
		try {
			conn.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
}
}
